import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class UserLogService extends BaseService<any> {
  private readonly logger = new Logger(UserLogService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: UserLogService_admin::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $field = 'id, ip, site_id, uid, username, operation, url, params, type, create_time';         $order = 'create_time desc';         $search_model = $th...
const field = 'id, ip, site_id, uid, username, operation, url, params, type, create_time';
        const order = 'create_time desc';
        const search_model = this.model.where([['site_id', '=', this.site_id))).withSearch(['username', 'create_time', 'uid', 'ip', 'type', 'url'), where).field(field).order(order];
        return this.pageQuery(search_model);
    }

    /**
     * 日志详情
     * @param int id
     * @return */
    async getInfo(int id){
        const where = [
            ['id', '=', id],
            ['site_id', '=', this.site_id)
        ];
        const field = 'id, ip, site_id, uid, username, operation, url, params, type, create_time';
        return this.model.where(where).field(field).findOrEmpty().toArray(];
    }

    /**
     * 添加用户（添加用户，不添加站点）
     * @param data
     * @return bool
     * @throws BusinessException
     */
    async add(data){
        data.site_id = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    async destroy()
    {
        this.sysUserLogService.whereRaw("1=1").delete(;
  }
  }

  /**
   * getInfo
   * 对应 PHP: UserLogService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $where = array(             ['id', '=', $id],             ['site_id', '=', $this->site_id]         );         $field = 'id, ip, site_id, uid, username...
const where = [
            ['id', '=', id],
            ['site_id', '=', this.site_id)
        ];
        const field = 'id, ip, site_id, uid, username, operation, url, params, type, create_time';
        return this.model.where(where).field(field).findOrEmpty().toArray(];
    }

    /**
     * 添加用户（添加用户，不添加站点）
     * @param data
     * @return bool
     * @throws BusinessException
     */
    async add(data){
        data.site_id = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    async destroy()
    {
        this.sysUserLogService.whereRaw("1=1").delete(;
  }
  }

  /**
   * add
   * 对应 PHP: UserLogService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $data['site_id'] = $this->site_id;         $res = $this->model->create($data);         return $res->id;     }      public function destroy()     {    ...
data.site_id = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    async destroy()
    {
        this.sysUserLogService.whereRaw("1=1").delete(];
    }
}
  }

  /**
   * destroy
   * 对应 PHP: UserLogService_admin::destroy()
   * 逻辑类型: undefined - undefined
   */
  async destroy() {
    // 基于PHP真实逻辑: destroy
    // PHP原文: (new SysUserLog())->whereRaw("1=1")->delete();     } }...
this.sysUserLogService.whereRaw("1=1").delete(];
    }
}
  }
}
